package com.deft.design.state;

import com.deft.design.state.event.*;
import com.deft.design.state.model.Result;
import com.deft.design.state.model.Status;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author Hide丶love
 * @date 2022/05/19
 **/
public class StateHandler {

    private final Map<Enum<Status>, AbstractState> stateMap = new ConcurrentHashMap<>();

    public StateHandler() {
        stateMap.put(Status.EDIT, new EditState());
        stateMap.put(Status.CHECK, new CheckState());
        stateMap.put(Status.PASS, new PassState());
        stateMap.put(Status.REFUSE, new RefuseState());
        stateMap.put(Status.DOING, new DoingState());
        stateMap.put(Status.CLOSE, new CloseState());
        stateMap.put(Status.OPEN, new OpenState());
    }

    public Result arraignment(String activityId, Enum<Status> status) {
        return stateMap.get(status).arraignment(activityId, status);
    }

    public Result checkPass(String activityId, Enum<Status> status) {
        return stateMap.get(status).checkPass(activityId, status);
    }

    public Result checkRefuse(String activityId, Enum<Status> currentStatus) {
        return stateMap.get(currentStatus).checkRefuse(activityId, currentStatus);
    }

    public Result checkRevoke(String activityId, Enum<Status> currentStatus) {
        return stateMap.get(currentStatus).checkRevoke(activityId, currentStatus);
    }

    public Result close(String activityId, Enum<Status> currentStatus) {
        return stateMap.get(currentStatus).close(activityId, currentStatus);
    }

    public Result open(String activityId, Enum<Status> currentStatus) {
        return stateMap.get(currentStatus).open(activityId, currentStatus);
    }

    public Result doing(String activityId, Enum<Status> currentStatus) {
        return stateMap.get(currentStatus).doing(activityId, currentStatus);
    }
}
